﻿#pragma once
#include "YTools.h"
#include "../format/YDemuxer.h"

//音视频同步枚举
enum YSYN_TYPE
{
	YSYN_NONE = 0,  //不做同步
	YSYN_VIDEO = 1, //根据视频同步，不处理音频
};
/// <summary>
/// 解封装任务类，集成YThread（责任链）
/// </summary>
class YDemuxerTask : public YThread
{

public:
	void Working();//线程执行的主函数
	/// <summary>
	/// 打开解封装
	/// </summary>
	/// <param name="url">rtsp地址</param>
	/// <param name="timeout_ms">超时时间 单位毫秒</param>
	/// <returns></returns>
	bool Open(std::string url, int timeout_ms = 1000);

	/// <summary>
	/// 复制视频参数
	/// </summary>
	/// <returns></returns>
	std::shared_ptr<YAVParameters> CopyVideoPara()
	{
		return demuxer_.CopyVideoParameters();
	}
	/// <summary>
	/// 复制音频参数
	/// </summary>
	/// <returns></returns>
	std::shared_ptr<YAVParameters> CopyAudioPara()
	{
		return demuxer_.CopyAudioParameters();
	}

	int getWidth()
	{
		return demuxer_.GetVideoWidth();
	}
	int getHeight() {
		return demuxer_.GetVideoHeight();
	}

	int getAudioIndex() { return demuxer_.GetAudioIndex(); }
	int getVideoIndex() { return demuxer_.GetVideoIndex(); }

	//设置音视频同步类型
	void set_syn_type(YSYN_TYPE t) { syn_type_ = t; }


	//seek到解封装的指定位置
	bool Seek(long long ms);


	YDemuxerTask();
	~YDemuxerTask();

private:
	YDemuxer demuxer_;
	std::string url_;
	int timeout_ms_ = 0;//超时时间
	YSYN_TYPE syn_type_ = YSYN_NONE;
};
